package com.wisezone.permission.web;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import com.wisezone.common.annotation.WzWebAnnotation;
import com.wisezone.common.exception.WzWebException;
import com.wisezone.common.utils.BeanUtils;
import com.wisezone.common.utils.ConstantUtils;
import com.wisezone.common.web.BaseController;
import com.wisezone.permission.bean.entity.WzGroupEntity;
import com.wisezone.permission.bean.entity.WzRoleEntity;
import com.wisezone.permission.bean.search.WzGroupSearch;
import com.wisezone.permission.service.WzGroupService;
/**
 *
 *用户组; InnoDB free: 24576 kB
 *@author create by 
 *create date 2010-07-29 14:44:41 update date 2010-07-29 14:44:41
 *
 */
@WzWebAnnotation(moduleName = "group")
public class WzGroupController extends BaseController<WzGroupEntity, WzGroupSearch>{

	/**
	  *
	  *
	  *
	  */
	private WzGroupService wzGroupService;
	
	private List<WzRoleEntity> roleList; // 角色列表
	
	private String roleIds;  //角色ID
	
	private String roleNames;  //角色名称

	/**
	 * 返回清空条件列表
	 * 
	 * @return
	 * @throws WzWebException
	 */
	public String toList() throws WzWebException {

		searchEntity = new WzGroupSearch();
		pagination = this.wzGroupService.listByPage(searchEntity);
		return LIST;
	}

	/**
	 * 获得列表
	 * 
	 * @return
	 * @throws Exception
	 */
	public String list() throws WzWebException {

		searchEntity = getSearchEntity();
		pagination = this.wzGroupService.listByPage(searchEntity);
		return LIST;
	}

	/**
	 * 进入新增
	 * 
	 * @return
	 * @throws Exception
	 */
	public String enterNew() throws WzWebException {

		if (id != null) {
			entity = this.wzGroupService.findById(id);
			entity.setId(null);
		}
		return NEW_EDIT;
	}

	/**
	 * 进入修改
	 * 
	 * @return
	 * @throws Exception
	 */
	public String enterEdit() throws WzWebException {

		entity = this.wzGroupService.findById(id);
		return NEW_EDIT;
	}

	/**
	 * 进入查看
	 * 
	 * @return
	 * @throws Exception
	 */
	public String enterView() throws WzWebException {

		entity = this.wzGroupService.findById(id);
		return VIEW;
	}

	/**
	 * 保存
	 * 
	 * @return
	 * @throws Exception
	 */
	public String save() throws WzWebException {

		entity = getEntity();
		entity.setState(ConstantUtils.STATE_EXIST);
		this.wzGroupService.saveOrUpdate(entity,roleIds);
		return toList();
	}

	/**
	 * 修改
	 * 
	 * @return
	 * @throws Exception
	 */
	public String update() throws WzWebException {

		entity = getEntity();
		WzGroupEntity oldEntity = this.wzGroupService.findById(id);
		BeanUtils.copyBean(oldEntity, entity);
		this.wzGroupService.saveOrUpdate(oldEntity,roleIds);
		return toList();
	}

	/**
	 * 删除
	 * 
	 * @return
	 * @throws Exception
	 */
	public String delete() throws WzWebException {

		Collection<Serializable> idList = getIdList();
		if (idList != null) {
			this.wzGroupService.delete(idList);
		}
		return toList();
	}

	public void setWzGroupService(WzGroupService wzGroupService) {
		this.wzGroupService = wzGroupService;
	}

	public String getRoleIds() {
		return roleIds;
	}

	public void setRoleIds(String roleIds) {
		this.roleIds = roleIds;
	}

	public String getRoleNames() {
		return roleNames;
	}

	public void setRoleNames(String roleNames) {
		this.roleNames = roleNames;
	}
	

}